
import { ref } from 'vue'
export default function (audio, musicList, randomMusicList, randomMusicIndex) {

    const modeMap = [
        {
            name: '顺序播放',
            icon: ''
        },
        {
            name: '单曲循环',
            icon: ''
        },
        {
            name: '随机播放',
            icon: ''
        },
        {
            name: '列表循环',
            icon: ''
        }
    ]

    let modeIndex = ref(0)

    function switchPlayMode() {

        modeIndex.value++
        if (modeIndex.value >= modeMap.length) {
            modeIndex.value = 0
        }

        if (modeMap[modeIndex.value].name === '单曲循环') {
            audio.value.setAttribute('loop', true)
        } else {
            audio.value.removeAttribute('loop')
        }

        if (modeMap[modeIndex.value].name === '随机播放') {
            randomMusicList.value = [...musicList.value].sort(() => {
                return Math.random() - 0.5
            })
            randomMusicIndex.value = 0

        }
    }

    return {
        modeMap,
        modeIndex,
        switchPlayMode
    }
}